//
//  OrderViewController.m
//  PigMarket
//
//  Created by mac on 2019/4/9.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "OrderViewController.h"
#import "PigVarietyView.h"
#import "PigBasicInformationView.h"
#import "PigPayFooterView.h"
#import "PayViewController.h"

@interface OrderViewController ()
/**
 顶部提示bg
 */
@property (nonatomic , strong) UIView *topTipsBgView;
/**
 顶部提示
 */
@property (nonatomic , strong)  YYLabel *topTipsLab;
/**
 varietyView
 */
@property (nonatomic , strong) PigVarietyView *varietyView;
/**
 infoView
 */
@property (nonatomic , strong) PigBasicInformationView *infoView;
/**
 footView
 */
@property (nonatomic , strong) PigPayFooterView *footerView;
/**
 footerInfoDic
 */
@property (nonatomic , strong) NSDictionary *footerInfoDic;
@end

@implementation OrderViewController

#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"99元预定";
    [self setUpView];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

#pragma mark - init method
- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}
- (void)initView {
    [self.view addSubview:self.topTipsBgView];
    [self.topTipsBgView addSubview:self.topTipsLab];
    [self.view addSubview:self.varietyView];
    [self.view addSubview:self.infoView];
    [self.view addSubview:self.footerView];
}

- (void) initLayout {
    [self.topTipsBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(58);
    }];
    [self.topTipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-10);
    }];
    [self.varietyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.topTipsBgView.mas_bottom).offset(10);
    }];
    [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.varietyView.mas_bottom).offset(10);
        make.left.right.mas_equalTo(0);
    }];
    [self.footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-20);
    }];
}

- (void) initAction {
    [self.footerView.confirmBtn addTarget:self action:@selector(confirmPayTapped) forControlEvents:UIControlEventTouchUpInside];
}

- (void)initData {


    self.varietyView.pigTitle.text = self.detailModel.varietiesName;
    self.varietyView.numLab.text = [NSString stringWithFormat:@"编号:%@",self.detailModel.pigNum];
    self.varietyView.personalRemarkLab.text = self.detailModel.personality;
    self.infoView.weightDetailLab.text = [NSString stringWithFormat:@"%.2fkg(%@)",self.detailModel.weight,self.detailModel.weighDate];
    self.infoView.priceDetailLab.text = self.detailModel.unitPrice;
    self.infoView.birthdayDetailLab.text = self.detailModel.birthDate;
    self.infoView.currentDaysDetailLab.text = [NSString stringWithFormat:@"%@天",self.detailModel.age];
    self.infoView.dateDetailLab.text = [NSString stringWithFormat:@"%@(饲养周期%@天)",self.detailModel.expectOutDate,self.detailModel.cycle];
    self.infoView.breedGroundDetailLab.text = self.detailModel.pigField;

    
    self.footerInfoDic = @{@"title":@"需付定金",
                           @"discount":@"",
                           @"confirmTitle":@"确认付款"};
    self.footerView.infoDic = self.footerInfoDic;
    self.footerView.priceLab.text = @"￥99";
}

#pragma mark - delegate

#pragma mark - target action
- (void)confirmPayTapped {
    
    PayViewController *payVC = [[PayViewController alloc] init];
    payVC.model = self.detailModel;
    payVC.adoptType = UnAdoptTypeOrder;
    payVC.actuallyPaymentMoney = @"99";
    payVC.owedPaymentMoney = @"99";
    [self.navigationController pushViewController:payVC animated:YES];
}
#pragma mark - private method

#pragma mark - getter and setter
- (UIView *)topTipsBgView {
    if (!_topTipsBgView) {
        _topTipsBgView = [[UIView alloc] init];
        _topTipsBgView.backgroundColor = [UIColor colorWithHexString:@"#FFF9D4"];
    }
    return _topTipsBgView;
}
- (YYLabel *)topTipsLab {
    if (!_topTipsLab) {
        _topTipsLab = [[YYLabel alloc] init];
        _topTipsLab.numberOfLines = 0;
        NSString *tipsStr = @"提示：此仔猪最多为您预留72小时，如您超过此时间仍未购买，小猪可被他人买走。同时您可通过客服申请退款。";
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:tipsStr];
        [attributedString yy_setFont:[UIFont smallFont] range:attributedString.yy_rangeOfAll];
        attributedString.yy_lineSpacing = 6;
        attributedString.yy_color = [UIColor colorWithHexString:@"EC8C00"];
        _topTipsLab.attributedText = attributedString;
    }
    return _topTipsLab;
}
- (PigVarietyView *)varietyView {
    if (!_varietyView) {
        _varietyView = [[PigVarietyView alloc] init];
        _varietyView.backgroundColor = [UIColor whiteColor];
    }
    return _varietyView;
}
- (PigBasicInformationView *)infoView {
    if (!_infoView) {
        _infoView = [[PigBasicInformationView alloc] init];
        _infoView.backgroundColor = [UIColor whiteColor];
    }
    return _infoView;
}
- (PigPayFooterView *)footerView {
    if (!_footerView) {
        _footerView = [[PigPayFooterView alloc] init];
        _footerView.backgroundColor = [UIColor whiteColor];
        
    }
    return _footerView;
}
@end
